<template>
  <div>
    <choose-video v-if="dataType == 1" :value.sync="current_value" :field="field" :form-datas="formDatas" />
    <choose-audio v-else-if="dataType == 2" :value.sync="current_value" :field="field" :form-datas="formDatas" />
    <choose-file v-else-if="dataType == 4" :value.sync="current_value" :field="field" :form-datas="formDatas" />
    <edu-editor v-else-if="dataType == 3" :key="field" :value.sync="txt_value" :args="{}" />
    <div v-else-if="dataType == 0 || !dataType" style="color: #F56C6C;">请选择课时类型</div>
    <div v-else>暂不支持该类型</div>
  </div>
</template>

<script>
import ChooseVideo from '@/pages/material/choose/video.vue';
import ChooseAudio from '@/pages/material/choose/audio.vue';
import ChooseFile from '@/pages/material/choose/file.vue';
import EduEditor from '@public/form/editor.vue';

export default {
  components: {
    ChooseVideo,
    ChooseAudio,
    ChooseFile,
    EduEditor
  },
  props: {
    value: {
      type: Number,
      default: 0
    },
    field: {
      type: String,
      required: true,
      default: ''
    },
    formDatas: {
      type: Object,
      required: true,
      default: _ => {
        return {};
      }
    }
  },
  data() {
    return {
      current_value: this.value,
      txt_value: this.formDatas.course_data_id_attach ? this.formDatas.course_data_id_attach.data_txt : ''
    };
  },
  computed: {
    dataType() {
      return this.formDatas.course_data_type;
    }
  },
  watch: {
    current_value(value) {
      this.$emit('update:value', value);
    },
    txt_value(value) {
      this.$emit('update:value', value);
    },
    dataType(type) {
      if (type == 3) {
        this.current_value = '';
      } else {
        this.current_value = 0;
      }
    }
  }
};
</script>
